/*
 * Copyright 2009 Prime Technology.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.primefaces.facestrace.phase;

import javax.faces.event.PhaseId;

import org.primefaces.facestrace.utils.TraceUtils;

public class PhaseData {
	
	private long beginTime;

	private long endTime;

	private PhaseId phaseId;

	private String phaseName;
	
	private boolean executed;
	
	private boolean causedResponse;

	public PhaseData(PhaseId phaseId, String phaseName) {
		this.phaseId = phaseId;
		this.phaseName = phaseName;
		executed = false;
		causedResponse = false;
	}

	public long getBeginTime() {
		return beginTime;
	}

	public void setBeginTime(long beginTime) {
		this.beginTime = beginTime;
	}

	public long getEndTime() {
		return endTime;
	}

	public void setEndTime(long endTime) {
		setExecuted(true);
		this.endTime = endTime;
	}

	public PhaseId getPhaseId() {
		return phaseId;
	}

	public void setPhaseId(PhaseId phaseId) {
		this.phaseId = phaseId;
	}

	public long getExecutionTime() {
		long time = endTime - beginTime;
		if(time < 0 )
			return TraceUtils.getCurrentTimeinMillis() - beginTime;
		else
			return time; 
	}

	public String getPhaseName() {
		return phaseName;
	}

	public void setPhaseName(String phaseName) {
		this.phaseName = phaseName;
	}
	
	public boolean isExecuted() {
		return executed;
	}
	
	public void setExecuted(boolean executed) {
		this.executed = executed;
	}
	
	public boolean isCausedResponse() {
		return causedResponse;
	}
	
	public void setCausedResponse(boolean causedResponse) {
		this.causedResponse = causedResponse;
	}
}